package com.feather.unit;

import java.io.*;
import com.feather.annotation.*;
public class FileActionUnit{

	private String root;
	
	
	@ActionMethod
	public String readTextFile(@InputParam(name="path") String path) throws Exception
	{
		File file = new File(root + path);
		
		
		if(file.isFile() && file.exists())
		{
			BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
			StringWriter stringWriter = new StringWriter();
			BufferedWriter writer = new BufferedWriter(stringWriter);
			
			String line = null;
			while((line = reader.readLine()) != null)
			{
				writer.write(line);
				writer.newLine();
			}
			
			writer.flush();
			return stringWriter.toString();
		}
		
		throw new Exception(path + " not found~");
		
	}


	public String getRoot() {
		return root;
	}

	public void setRoot(String root) {
		this.root = root;
	}

}
